package com.jctrip.hotel.boot.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.acl.common.AclClientRPCHook;
import org.apache.rocketmq.acl.common.SessionCredentials;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.remoting.RPCHook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rocketmq配置类
 */
@Slf4j
@Configuration
public class RocketMqConfig {

    private String namesrv = "rmq-cn-jte3l6xuf1m-vpc.cn-hangzhou.rmq.aliyuncs.com:8080";

    private String accessKey = "KUQ7xFQpstB7WiG7";

    private String secretKey = "h3MKF7Q748gt78s6";

//    @Bean(initMethod = "start", destroyMethod = "shutdown", name = "incrHotelDefaultMQProducer")
//    public DefaultMQProducer incrHotelDefaultMQProducer() {
//        RPCHook rpcHook = new AclClientRPCHook(new SessionCredentials(accessKey, secretKey));
//        DefaultMQProducer producer = new DefaultMQProducer("incrHotelId", rpcHook);
//        producer.setNamesrvAddr(namesrv);
//        producer.setVipChannelEnabled(false);
//        return producer;
//    }
//
//    @Bean(initMethod = "start", destroyMethod = "shutdown", name = "hotelCallbackDefaultMQProducer")
//    public DefaultMQProducer hotelCallbackDefaultMQProducer() {
//        RPCHook rpcHook = new AclClientRPCHook(new SessionCredentials(accessKey, secretKey));
//        DefaultMQProducer producer = new DefaultMQProducer("hotelCallback", rpcHook);
//        producer.setNamesrvAddr(namesrv);
//        producer.setVipChannelEnabled(false);
//        return producer;
//    }

    @Bean(initMethod = "start", destroyMethod = "shutdown", name = "poiCallbackDefaultMQProducer")
    public DefaultMQProducer poiCallbackDefaultMQProducer() {
        RPCHook rpcHook = new AclClientRPCHook(new SessionCredentials(accessKey, secretKey));
        DefaultMQProducer producer = new DefaultMQProducer("hotelCallback", rpcHook);
        producer.setNamesrvAddr(namesrv);
        producer.setVipChannelEnabled(false);
        return producer;
    }
}
